package kn.cstf2.cop.Client;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
import java.util.logging.Level;
import kn.cstf2.cop.Bean.*;
import kn.cstf2.cop.Shared.CopShared;
import kn.cstf2.cop.Server.CopServer;
import kn.cstf2.global.Utils.ConexionFtp;
import kn.cstf2.global.Utils.CstF2Exception;
import kn.cstf2.implementation.Bean.ClienteStkBean;
import kn.cstf2.implementation.Bean.T_asignStkBean;
import kn.cstf2.implementation.Bean.TransitionsBeanImp;
import kn.cstf2.main.Shared.MainShared;
import kn.cstf2.transition.Bean.TransitionBean;
import kn.cstf2.transition.Client.TransitionClient;
import kn.cstf2.transition.Shared.TransitionShared;
import kn.mx.cstf2.dto.UsuarioDto;
import kn.mx.cstf2.dto.UsuarioDto;

import org.apache.log4j.Logger;

public class CopActionExport extends ActionSupport {

    private static Logger log = Logger.getLogger(TransitionClient.class);
    public static final String ERROR_SESSION = "errorSession";
    public static final String ERROR_KNKEY = "errorKnkey";
    public String ZIP = "zip";
    private String exporta;
    private TransitionBean transitionBeanM = new TransitionBean();
    private TransitionBean transitionBean = new TransitionBean();
    private Boolean gralVobo;
    private Boolean gralVoboSop;
    private T_clientesStkBean financialBI = new T_clientesStkBean();
    private String s1;
    private String delete;
    //private String fileNameUpload;
    private File fileNameUpload;
//    public String getFileNameUpload() {
//        return fileNameUpload;
//    }
//
//    public void setFileNameUpload(String fileNameUpload) {
//        this.fileNameUpload = fileNameUpload;
//    }
    ContactsBean contactsBean = null;
    private ArrayList<String> contactsList = new ArrayList<String>();
    private String requierementsTxt;
    private CopBean subproducts = new CopBean();
    private String originConditionsTxt;
    private String destinationConditionsTxt;
    private String workingInstructionsTxt;
    private String fileListOnServerSelected;
    private InputStream fileInputStream;
    private ArrayList<String> fileListOnServer = new ArrayList<String>();
    ;
    
    private ArrayList<String> creditTermsList = new ArrayList<String>();
    private ArrayList<String> billingCurrencyList = new ArrayList<String>();
    private ArrayList<String> invoiceRevDate = new ArrayList<String>();
    private ArrayList<String> invoiceReceDate = new ArrayList<String>();
    private ArrayList<String> fileAttachList = new ArrayList<String>();
    private ClienteStkBean cp = new ClienteStkBean();
    private ExceptionBean exceptionBean = new ExceptionBean();
    private KpiBean kpiBean = new KpiBean();
    private ArrayList<ContactsBean> detallesContactsList;
    private ArrayList<KpiBean> detalleSpecialList = new ArrayList<KpiBean>();
    private ArrayList<ExceptionBean> detallesExceptionList;
    private T_customer_solutionBeanSTK t_customer_solutionBeanSTK = new T_customer_solutionBeanSTK();
    private CopBean copBeanJSP = new CopBean();

    public CopBean getCopBeanJSP() {
        return copBeanJSP;
    }

    public void setCopBeanJSP(CopBean copBeanJSP) {
        this.copBeanJSP = copBeanJSP;
    }

    public T_customer_solutionBeanSTK getT_customer_solutionBeanSTK() {
        return t_customer_solutionBeanSTK;
    }

    public void setT_customer_solutionBeanSTK(T_customer_solutionBeanSTK t_customer_solutionBeanSTK) {
        this.t_customer_solutionBeanSTK = t_customer_solutionBeanSTK;
    }

    public KpiBean getKpiBean() {
        return kpiBean;
    }

    public void setKpiBean(KpiBean kpiBean) {
        this.kpiBean = kpiBean;
    }

    public ExceptionBean getExceptionBean() {
        return exceptionBean;
    }

    public void setExceptionBean(ExceptionBean exceptionBean) {
        this.exceptionBean = exceptionBean;
    }

    public ArrayList<ExceptionBean> getDetallesExceptionList() {
        return detallesExceptionList;
    }

    public void setDetallesExceptionList(ArrayList<ExceptionBean> detallesExceptionList) {
        this.detallesExceptionList = detallesExceptionList;
    }

    public ArrayList<KpiBean> getDetalleSpecialList() {
        return detalleSpecialList;
    }

    public void setDetalleSpecialList(ArrayList<KpiBean> detalleSpecialList) {
        this.detalleSpecialList = detalleSpecialList;
    }

    public ArrayList<String> getFileAttachList() {
        return fileAttachList;
    }

    public void setFileAttachList(ArrayList<String> fileAttachList) {
        this.fileAttachList = fileAttachList;
    }

    public String getS1() {
        return s1;
    }

    public void setS1(String s1) {
        this.s1 = s1;
    }

    public String getDelete() {
        return delete;
    }

    public void setDelete(String delete) {
        this.delete = delete;
    }

    public File getFileNameUpload() {
        return fileNameUpload;
    }

    public void setFileNameUpload(File fileNameUpload) {
        this.fileNameUpload = fileNameUpload;
    }

    public T_clientesStkBean getFinancialBI() {
        return financialBI;
    }

    public void setFinancialBI(T_clientesStkBean financialBI) {
        this.financialBI = financialBI;
    }

    public ArrayList<ContactsBean> getDetallesContactsList() {
        return detallesContactsList;
    }

    public void setDetallesContactsList(ArrayList<ContactsBean> detallesContactsList) {
        this.detallesContactsList = detallesContactsList;
    }

    public ClienteStkBean getCp() {
        return cp;
    }

    public void setCp(ClienteStkBean cp) {
        this.cp = cp;
    }

    public InputStream getFileInputStream() {
        return fileInputStream;
    }

    public void setFileInputStream(InputStream fileInputStream) {
        this.fileInputStream = fileInputStream;
    }

    public String getFileListOnServerSelected() {
        return fileListOnServerSelected;
    }

    public void setFileListOnServerSelected(String fileListOnServerSelected) {
        this.fileListOnServerSelected = fileListOnServerSelected;
    }

    public ArrayList<String> getBillingCurrencyList() {
        return billingCurrencyList;
    }

    public void setBillingCurrencyList(ArrayList<String> billingCurrencyList) {
        this.billingCurrencyList = billingCurrencyList;
    }

    public ArrayList<String> getCreditTermsList() {
        return creditTermsList;
    }

    public void setCreditTermsList(ArrayList<String> creditTermsList) {
        this.creditTermsList = creditTermsList;
    }

    public ArrayList<String> getInvoiceReceDate() {
        return invoiceReceDate;
    }

    public void setInvoiceReceDate(ArrayList<String> invoiceReceDate) {
        this.invoiceReceDate = invoiceReceDate;
    }

    public ArrayList<String> getInvoiceRevDate() {
        return invoiceRevDate;
    }

    public void setInvoiceRevDate(ArrayList<String> invoiceRevDate) {
        this.invoiceRevDate = invoiceRevDate;
    }

    public ArrayList<String> getFileListOnServer() {
        return fileListOnServer;
    }

    public void setFileListOnServer(ArrayList<String> fileListOnServer) {
        this.fileListOnServer = fileListOnServer;
    }

    public String getWorkingInstructionsTxt() {
        return workingInstructionsTxt;
    }

    public void setWorkingInstructionsTxt(String workingInstructionsTxt) {
        this.workingInstructionsTxt = workingInstructionsTxt;
    }

    public String getDestinationConditionsTxt() {
        return destinationConditionsTxt;
    }

    public void setDestinationConditionsTxt(String destinationConditionsTxt) {
        this.destinationConditionsTxt = destinationConditionsTxt;
    }

    public String getOriginConditionsTxt() {
        return originConditionsTxt;
    }

    public void setOriginConditionsTxt(String originConditionsTxt) {
        this.originConditionsTxt = originConditionsTxt;
    }

    public CopBean getSubproducts() {
        return subproducts;
    }

    public void setSubproducts(CopBean subproducts) {
        this.subproducts = subproducts;
    }

    public String getRequierementsTxt() {
        return requierementsTxt;
    }

    public void setRequierementsTxt(String requierementsTxt) {
        this.requierementsTxt = requierementsTxt;
    }

    public ArrayList<String> getContactsList() {
        return contactsList;
    }

    public void setContactsList(ArrayList<String> contactsList) {
        this.contactsList = contactsList;
    }

    public ContactsBean getContactsBean() {
        return contactsBean;
    }

    public void setContactsBean(ContactsBean contactsBean) {
        this.contactsBean = contactsBean;
    }

    public String getExporta() {
        return exporta;
    }

    public void setExporta(String exporta) {
        this.exporta = exporta;
    }

    public TransitionBean getTransitionBean() {
        return transitionBean;
    }

    public void setTransitionBean(TransitionBean transitionBean) {
        this.transitionBean = transitionBean;
    }

    public TransitionBean getTransitionBeanM() {
        return transitionBeanM;
    }

    public void setTransitionBeanM(TransitionBean transitionBeanM) {
        this.transitionBeanM = transitionBeanM;
    }
    private ArrayList<TransitionBean> transitionBeanArray;

    public ArrayList<TransitionBean> getTransitionBeanArray() {
        return transitionBeanArray;
    }

    public void setTransitionBeanArray(ArrayList<TransitionBean> transitionBeanArray) {
        this.transitionBeanArray = transitionBeanArray;
    }

    public String execute() {
        try {
            UsuarioDto usuario= new UsuarioDto();
            ActionContext contexto = ActionContext.getContext();
            Map<String, Object> sesion = contexto.getSession();
            usuario = (UsuarioDto) sesion.get("UsuarioSession");
            Map<String, Object> sesion2 = contexto.getSession();
            transitionBeanM = (TransitionBean) sesion2.get("Knkey");

            contactsList.add("SU");
            contactsList.add("RU");
            contactsList.add("Guest");

            if (transitionBeanM.getKnkey() == null) {
                CstF2Exception ex = new CstF2Exception();
                log.error("ERROR. ", ex);
                addFieldError("Not Knkey Found", "PorFavor Seleccione una Knkey: " + ex.getMessage());
                MainShared mainShared = new MainShared();
                setTransitionBeanArray(mainShared.GetTransitionBeanArrayIdKnkey(usuario));

                return ERROR_KNKEY;
            }

            transitionBeanM = (TransitionBean) sesion2.get("Knkey");

            //String e = getExporta();

            CopShared copShared = new CopShared();
            ClienteStkBean clienteStkBean = new ClienteStkBean();
            TransitionShared transitionShared = new TransitionShared();

            cp = copShared.GetAllDataFromClientesSTK(transitionBeanM.getKnkey());
            clienteStkBean = copShared.GetAcountVisibilitySTK(transitionBeanM.getKnkey());
            cp.setAccounts_visibility(clienteStkBean.getAccounts_visibility());

            t_customer_solutionBeanSTK = copShared.GetCustomerSolutionStk(transitionBeanM.getKnkey());

            TransitionBean transitionBeanNew = new TransitionBean();
            transitionBeanNew = transitionShared.GetTransitionBeanIdKnkey(transitionBeanM);
            transitionBeanM = transitionBeanNew;

            exporta = "false";
            subproducts = copShared.GetDataFromCop(transitionBeanM.getId(), false);

            detalleSpecialList = copShared.GetKpiSTK(subproducts.getId());
            detallesExceptionList = copShared.GetExceptionListSTK(subproducts.getId());

            copBeanJSP = copShared.GetDataFromCop(transitionBeanM.getId(), false);

            ConexionFtp conexionFtp = new ConexionFtp();
            fileListOnServer = conexionFtp.enlistaDir(transitionBeanM.getKnkey());

        } catch (CstF2Exception ex) {
            log.error("ERROR. ", ex);
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        }
        return SUCCESS;
    }

    public String GetAllDataFroSTK() {
        try {
            UsuarioDto usuario = new UsuarioDto();
            ActionContext contexto = ActionContext.getContext();
            Map<String, Object> sesion = contexto.getSession();
            usuario = (UsuarioDto) sesion.get("UsuarioSession");
            Map<String, Object> sesion2 = contexto.getSession();
            transitionBeanM = (TransitionBean) sesion2.get("Knkey");

            CopShared copShared = new CopShared();
            ClienteStkBean clienteStkBean = new ClienteStkBean();

            clienteStkBean = copShared.GetAllDataFromClientesSTK(transitionBeanM.getKnkey());


        } catch (CstF2Exception ex) {
            log.error("ERROR. ", ex);
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        }
        return SUCCESS;
    }

    public String ExportCop() {
        try {
            UsuarioDto usuario = new UsuarioDto();
            ActionContext contexto = ActionContext.getContext();
            Map<String, Object> sesion = contexto.getSession();
            usuario = (UsuarioDto) sesion.get("UsuarioSession");
            Map<String, Object> sesion2 = contexto.getSession();
            transitionBeanM = (TransitionBean) sesion2.get("Knkey");

            TransitionShared transitionShared = new TransitionShared();
            CopShared copShared = new CopShared();

            TransitionBean transitionBeanNew = new TransitionBean();
            transitionBeanNew = transitionShared.GetTransitionBeanIdKnkey(transitionBeanM);
            transitionBeanM = transitionBeanNew;

            CopBean copBean = new CopBean();
            copBean = copShared.GetDataFromCop(transitionBeanM.getId(), false);
            if (copBean.getId() == null) {
                copShared.InsertDefaultValuesEnCop(false, transitionBeanM.getId());
            }


        } catch (CstF2Exception ex) {
            log.error("ERROR. ", ex);
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        }
        return SUCCESS;
    }

    public String AssingContactC03False() {
        try {
            UsuarioDto usuario = new UsuarioDto();
            ActionContext contexto = ActionContext.getContext();
            Map<String, Object> sesion = contexto.getSession();
            usuario = (UsuarioDto) sesion.get("UsuarioSession");
            Map<String, Object> sesion2 = contexto.getSession();
            transitionBeanM = (TransitionBean) sesion2.get("Knkey");

            contactsList.add("SU");
            contactsList.add("GUEST");
            contactsList.add("RU");

            TransitionShared transitionShared = new TransitionShared();
            CopShared copShared = new CopShared();
            CopBean copBean = new CopBean();

            TransitionBean transitionBeanNew = new TransitionBean();
            transitionBeanNew = transitionShared.GetTransitionBeanIdKnkey(transitionBeanM);
            transitionBeanM = transitionBeanNew;

            //setExporta(false);
            copBean = copShared.GetDataFromCop(transitionBeanM.getId(), false);
            contactsBean.setIdcop(copBean.getId());
            //ContactsBean contactsBean = new ContactsBean();
            copShared.InsertIntoContats(contactsBean);  //lo q hay desde el jsp

            Map<String, Object> sesionListP = contexto.getSession();
            detallesContactsList = (ArrayList<ContactsBean>) sesionListP.get("ListaContacts");

            if (detallesContactsList == null) {
                detallesContactsList = new ArrayList<ContactsBean>();

                detallesContactsList.add(contactsBean);

            } else {
                detallesContactsList.add(contactsBean);
            }
            sesionListP.put("ListaContacts", detallesContactsList);

            transitionBeanM.setTime(copShared.GetTheDateTime());
            transitionBeanM.setContacts(true);

//        java.util.Date utilDate = new java.util.Date(); //se convierte de java.util.Date a java.sql.Date
//        utilDate= transitionBeanM.getTime();
//        java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());

            TransitionsBeanImp tbdate2 = new TransitionsBeanImp();
            Date date = new Date();
            DateFormat dateFormatCQL = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy");
            String fecha = dateFormatCQL.format(date);

            transitionBeanM.setContactsDate(fecha);

            copShared.UpdateContactsyContacsDateIntoTransitions(transitionBeanM);


        } catch (CstF2Exception ex) {
            log.error("ERROR. ", ex);
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        }
        return SUCCESS;
    }

    public String DeletePersonAsContac04tFalse() {
        try {
            UsuarioDto usuario = new UsuarioDto();
            ActionContext contexto = ActionContext.getContext();
            Map<String, Object> sesion = contexto.getSession();
            usuario = (UsuarioDto) sesion.get("UsuarioSession");
            Map<String, Object> sesion2 = contexto.getSession();
            transitionBeanM = (TransitionBean) sesion2.get("Knkey");


            TransitionShared transitionShared = new TransitionShared();
            CopShared copShared = new CopShared();
            CopBean copBean = new CopBean();

            TransitionBean transitionBeanNew = new TransitionBean();
            transitionBeanNew = transitionShared.GetTransitionBeanIdKnkey(transitionBeanM);
            transitionBeanM = transitionBeanNew;

            copBean = copShared.GetDataFromCop(transitionBeanM.getId(), false);

            ContactsBean contactsBeanId = new ContactsBean();
            contactsBeanId = copShared.GetDatosDeContacts(copBean.getId());

            copShared.DeleteContacto(contactsBeanId.getIdcop());

            copShared.ContarContactosEnTransitions(transitionBeanM.getId());


        } catch (CstF2Exception ex) {
            log.error("ERROR. ", ex);
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        }
        return SUCCESS;
    }

    public String SaveInfoUser05() {
        try {
            UsuarioDto usuario = new UsuarioDto();
            ActionContext contexto = ActionContext.getContext();
            Map<String, Object> sesion = contexto.getSession();
            usuario = (UsuarioDto) sesion.get("UsuarioSession");
            Map<String, Object> sesion2 = contexto.getSession();
            transitionBeanM = (TransitionBean) sesion2.get("Knkey");


            TransitionShared transitionShared = new TransitionShared();
            CopShared copShared = new CopShared();
            CopBean copBean = new CopBean();
            ClienteStkBean clienteStkBean = new ClienteStkBean();

            TransitionBean transitionBeanNew = new TransitionBean();
            transitionBeanNew = transitionShared.GetTransitionBeanIdKnkey(transitionBeanM);
            transitionBeanM = transitionBeanNew;

            TransitionsBeanCop transitionsBeanCop = new TransitionsBeanCop();

            if (requierementsTxt.length() > 4) {
                transitionsBeanCop.setReporting(true);
                transitionsBeanCop.setId(transitionBeanM.getId());

                copShared.UpdateReportingTransition(transitionsBeanCop);
            }

            if (subproducts.getFcl() == true || subproducts.getLcl() == true || subproducts.getPerishables() == true || subproducts.getBrokerage() == true || subproducts.getIntermodal() || subproducts.getInsurance() == true) {
                transitionsBeanCop.setScopeofservice(true);
                transitionsBeanCop.setId(transitionBeanM.getId());

                copShared.UpdateScopeOfServiceTransition(transitionsBeanCop);
            }

            if (originConditionsTxt.length() > 4 || destinationConditionsTxt.length() > 4) {
                transitionsBeanCop.setCondition(true);
                transitionsBeanCop.setId(transitionBeanM.getId());

                copShared.UpdateConditionTransition(transitionsBeanCop);
            }

            if (workingInstructionsTxt.length() > 4) {
                transitionsBeanCop.setWorkingst(true);
                transitionsBeanCop.setId(transitionBeanM.getId());

                copShared.UpdateWorkingSTTransition(transitionsBeanCop);
            }

            if (gralVoboSop == true) {
                transitionsBeanCop.setSop(true);
                transitionsBeanCop.setId(transitionBeanM.getId());

                copShared.UpdateWorkingSTTransition(transitionsBeanCop);
            }

            if (subproducts.getPickuptosiling() == true || subproducts.getCustomsclearance() == true || subproducts.getMaincarriage() == true || subproducts.getArrivaltocustoms() == true || subproducts.getArrivaltodelivery()) {
                transitionsBeanCop.setKpi(true);
                transitionsBeanCop.setId(transitionBeanM.getId());

                copShared.UpdateKpiTransition(transitionsBeanCop);
            }

            if (financialBI != null) {
                transitionsBeanCop.setBilling(true);
                transitionsBeanCop.setId(transitionBeanM.getId());

                copShared.UpdateContactsTransition(transitionsBeanCop);
            }

            if (gralVobo == true) {
                transitionsBeanCop.setCop(true);
                transitionsBeanCop.setId(transitionBeanM.getId());

                copShared.UpdateContactsTransition(transitionsBeanCop);
            }

            if (detallesContactsList != null) {
                transitionsBeanCop.setContacts(true);
                transitionsBeanCop.setId(transitionBeanM.getId());

                copShared.UpdateContactsTransition(transitionsBeanCop);
            }

            subproducts = copShared.GetDataFromCop(transitionBeanM.getId(), false);
            copShared.UpdateCop(subproducts);

            transitionsBeanCop = copShared.SelectAllDataFromTransition(transitionBeanM.getId());
            copShared.UpdateTransition(transitionsBeanCop);


        } catch (CstF2Exception ex) {
            log.error("ERROR. ", ex);
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        }
        return SUCCESS;
    }

    public String UploadtxtLogAlert06() {
        try {
            UsuarioDto UsuarioDto = new UsuarioDto();
            ActionContext contexto = ActionContext.getContext();
            Map<String, Object> sesion = contexto.getSession();
            UsuarioDto = (UsuarioDto) sesion.get("UsuarioSession");
            Map<String, Object> sesion2 = contexto.getSession();
            transitionBeanM = (TransitionBean) sesion2.get("Knkey");

            TransitionShared transitionShared = new TransitionShared();
            CopShared copShared = new CopShared();
            CopBean copBean = new CopBean();
            ClienteStkBean clienteStkBean = new ClienteStkBean();

            TransitionBean transitionBeanNew = new TransitionBean();
            transitionBeanNew = transitionShared.GetTransitionBeanIdKnkey(transitionBeanM);
            transitionBeanM = transitionBeanNew;


            ConexionFtp conexionFtp = new ConexionFtp();
            File name = getFileNameUpload();
            String n = name.getPath();

            setS1("c:\\consultas.rar");
            //File firstLocalFile = new File("c:/consultas.rar");
            File firstLocalFile = new File(n);

            String firstRemoteFile = "consultas.rar";
            String nombre = firstLocalFile.getName();
            FileInputStream inputStream = new FileInputStream(name);
            //FileInputStream inputStream = new FileInputStream(firstLocalFile);

            System.out.println("Start uploading first file");
            boolean done = conexionFtp.guarda(nombre, "attachments", inputStream);

            fileListOnServer = conexionFtp.enlistaDir(transitionBeanM.getKnkey());

            inputStream.close();
            if (done) {
                System.out.println("The first file is uploaded successfully.");
            }

        } catch (CstF2Exception ex) {
            log.error("ERROR. ", ex);
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        } catch (Exception ex) {
            log.error("ERROR. ", ex);
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        }
        return SUCCESS;
    }

    public String downloadFileAction() {
        try {
            UsuarioDto UsuarioDto = new UsuarioDto();
            ActionContext contexto = ActionContext.getContext();
            Map<String, Object> sesion = contexto.getSession();
            UsuarioDto = (UsuarioDto) sesion.get("UsuarioSession");
            Map<String, Object> sesion2 = contexto.getSession();
            transitionBeanM = (TransitionBean) sesion2.get("Knkey");

            TransitionShared transitionShared = new TransitionShared();
            CopShared copShared = new CopShared();
            CopBean copBean = new CopBean();
            ClienteStkBean clienteStkBean = new ClienteStkBean();

            TransitionBean transitionBeanNew = new TransitionBean();
            transitionBeanNew = transitionShared.GetTransitionBeanIdKnkey(transitionBeanM);
            transitionBeanM = transitionBeanNew;


            ConexionFtp conexionFtp = new ConexionFtp();

            fileInputStream = conexionFtp.obtenInfo(getFileListOnServerSelected());

            fileListOnServer = conexionFtp.getNombresArchivos();

        } catch (CstF2Exception ex) {
            log.error("ERROR. ", ex);
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        } catch (Exception ex) {
            log.error("ERROR. ", ex);
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        }
        return ZIP;
    }

    public String deleteFileAction() {
        try {
            UsuarioDto UsuarioDto = new UsuarioDto();
            ActionContext contexto = ActionContext.getContext();
            Map<String, Object> sesion = contexto.getSession();
            UsuarioDto = (UsuarioDto) sesion.get("UsuarioSession");
            Map<String, Object> sesion2 = contexto.getSession();
            transitionBeanM = (TransitionBean) sesion2.get("Knkey");

            TransitionShared transitionShared = new TransitionShared();
            CopShared copShared = new CopShared();
            CopBean copBean = new CopBean();
            ClienteStkBean clienteStkBean = new ClienteStkBean();

            TransitionBean transitionBeanNew = new TransitionBean();
            transitionBeanNew = transitionShared.GetTransitionBeanIdKnkey(transitionBeanM);
            transitionBeanM = transitionBeanNew;


            ConexionFtp conexionFtp = new ConexionFtp();

            conexionFtp.borra(getFileListOnServerSelected(), "attachments");

            fileListOnServer = conexionFtp.enlistaDir(transitionBeanM.getKnkey());

        } catch (CstF2Exception ex) {
            log.error("ERROR. ", ex);
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        } catch (Exception ex) {
            log.error("ERROR. ", ex);
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        }
        return SUCCESS;
    }

    public String AssingExceptionFalse() {
        try {
            UsuarioDto UsuarioDto = new UsuarioDto();
            ActionContext contexto = ActionContext.getContext();
            Map<String, Object> sesion = contexto.getSession();
            UsuarioDto = (UsuarioDto) sesion.get("UsuarioSession");
            Map<String, Object> sesion2 = contexto.getSession();
            transitionBeanM = (TransitionBean) sesion2.get("Knkey");

            TransitionShared transitionShared = new TransitionShared();
            CopShared copShared = new CopShared();
            CopBean copBean = new CopBean();
            ClienteStkBean clienteStkBean = new ClienteStkBean();

            TransitionBean transitionBeanNew = new TransitionBean();
            transitionBeanNew = transitionShared.GetTransitionBeanIdKnkey(transitionBeanM);
            transitionBeanM = transitionBeanNew;

            String e = getExporta();
            //setExporta(false);
            copBean = copShared.GetDataFromCop(transitionBeanM.getId(), false);

            copShared.InsertExceptionSTK(exceptionBean, copBean.getId());

            execute();

        } catch (CstF2Exception ex) {
            log.error("ERROR. ", ex);
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        } catch (Exception ex) {
            log.error("ERROR. ", ex);
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        }
        return SUCCESS;
    }

    public String AssingKpiFalse() {
        try {
            UsuarioDto UsuarioDto = new UsuarioDto();
            ActionContext contexto = ActionContext.getContext();
            Map<String, Object> sesion = contexto.getSession();
            UsuarioDto = (UsuarioDto) sesion.get("UsuarioSession");
            Map<String, Object> sesion2 = contexto.getSession();
            transitionBeanM = (TransitionBean) sesion2.get("Knkey");

            TransitionShared transitionShared = new TransitionShared();
            CopShared copShared = new CopShared();
            CopBean copBean = new CopBean();
            ClienteStkBean clienteStkBean = new ClienteStkBean();

            TransitionBean transitionBeanNew = new TransitionBean();
            transitionBeanNew = transitionShared.GetTransitionBeanIdKnkey(transitionBeanM);
            transitionBeanM = transitionBeanNew;

            copBean = copShared.GetDataFromCop(transitionBeanM.getId(), false);
            copShared.InsertKpisSTK(kpiBean, copBean.getId());

            execute();

        } catch (CstF2Exception ex) {
            log.error("ERROR. ", ex);
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        } catch (Exception ex) {
            log.error("ERROR. ", ex);
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        }
        return SUCCESS;
    }

    public String GetDataClientFromSTK() {
        try {
            UsuarioDto UsuarioDto = new UsuarioDto();
            ActionContext contexto = ActionContext.getContext();
            Map<String, Object> sesion = contexto.getSession();
            UsuarioDto = (UsuarioDto) sesion.get("UsuarioSession");
            Map<String, Object> sesion2 = contexto.getSession();
            transitionBeanM = (TransitionBean) sesion2.get("Knkey");


            TransitionShared transitionShared = new TransitionShared();
            CopShared copShared = new CopShared();
            CopBean copBean = new CopBean();
            ClienteStkBean clienteStkBean = new ClienteStkBean();

            TransitionBean transitionBeanNew = new TransitionBean();
            transitionBeanNew = transitionShared.GetTransitionBeanIdKnkey(transitionBeanM);
            transitionBeanM = transitionBeanNew;

            clienteStkBean = copShared.GetAllDataFromClientesSTK(transitionBeanM.getKnkey());

            T_asignStkBean t_asignStkBean = new T_asignStkBean();
            t_asignStkBean = copShared.GetIfOwnerFromSTK(transitionBeanM.getKnkey());

        } catch (CstF2Exception ex) {
            log.error("ERROR. ", ex);
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        }

        return SUCCESS;
    }

    public String GetInputInfoFromCop() {
        try {
            UsuarioDto UsuarioDto = new UsuarioDto();
            ActionContext contexto = ActionContext.getContext();
            Map<String, Object> sesion = contexto.getSession();
            UsuarioDto = (UsuarioDto) sesion.get("UsuarioSession");
            Map<String, Object> sesion2 = contexto.getSession();
            transitionBeanM = (TransitionBean) sesion2.get("Knkey");


            TransitionShared transitionShared = new TransitionShared();
            CopShared copShared = new CopShared();
            CopBean copBean = new CopBean();
            ClienteStkBean clienteStkBean = new ClienteStkBean();

            TransitionBean transitionBeanNew = new TransitionBean();
            transitionBeanNew = transitionShared.GetTransitionBeanIdKnkey(transitionBeanM);
            transitionBeanM = transitionBeanNew;


            copBean = copShared.GetDataFromCop(transitionBeanM.getId(), false);

            Boolean exporta1 = false;
            copShared.InsertDefaultValuesEnCop(false, transitionBeanM.getId());

            Boolean exporta2 = true;
            copShared.InsertDefaultValuesEnCop(true, transitionBeanM.getId());

        } catch (CstF2Exception ex) {
            log.error("ERROR. ", ex);
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        }
        return SUCCESS;

    }

    public String AssingContactC10True() {
        try {
            UsuarioDto UsuarioDto = new UsuarioDto();
            ActionContext contexto = ActionContext.getContext();
            Map<String, Object> sesion = contexto.getSession();
            UsuarioDto = (UsuarioDto) sesion.get("UsuarioSession");
            Map<String, Object> sesion2 = contexto.getSession();
            transitionBeanM = (TransitionBean) sesion2.get("Knkey");


            TransitionShared transitionShared = new TransitionShared();
            CopShared copShared = new CopShared();
            CopBean copBean = new CopBean();

            TransitionBean transitionBeanNew = new TransitionBean();
            transitionBeanNew = transitionShared.GetTransitionBeanIdKnkey(transitionBeanM);
            transitionBeanM = transitionBeanNew;

            copBean = copShared.GetDataFromCop(transitionBeanM.getId(), false);

            Boolean exporta2 = true;
            copShared.InsertIntoContats(contactsBean);  //lo q hay desde el jsp

            transitionBeanM.setTime(copShared.GetTheDateTime());

            transitionBeanM.setContacts(true);

//        java.util.Date utilDate = new java.util.Date(); //se convierte de java.util.Date a java.sql.Date
//        utilDate= transitionBeanM.getTime();
//        java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());

            TransitionsBeanImp tbdate2 = new TransitionsBeanImp();
            Date date = new Date();
            DateFormat dateFormatCQL = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy");
            String fecha = dateFormatCQL.format(date);

            transitionBeanM.setContactsDate(fecha);

            copShared.UpdateContactsyContacsDateIntoTransitions(transitionBeanM);

        } catch (CstF2Exception ex) {
            log.error("ERROR. ", ex);
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;
        }
        return SUCCESS;
    }

    public String DeletePersonAsContac11True() {
        try {
            UsuarioDto UsuarioDto = new UsuarioDto();
            ActionContext contexto = ActionContext.getContext();
            Map<String, Object> sesion = contexto.getSession();
            UsuarioDto = (UsuarioDto) sesion.get("UsuarioSession");
            Map<String, Object> sesion2 = contexto.getSession();
            transitionBeanM = (TransitionBean) sesion2.get("Knkey");

            TransitionShared transitionShared = new TransitionShared();
            CopShared copShared = new CopShared();
            CopBean copBean = new CopBean();

            TransitionBean transitionBeanNew = new TransitionBean();
            transitionBeanNew = transitionShared.GetTransitionBeanIdKnkey(transitionBeanM);
            transitionBeanM = transitionBeanNew;


            copBean = copShared.GetDataFromCop(transitionBeanM.getId(), false);

            ContactsBean contactsBeanId = new ContactsBean();
            contactsBeanId = copShared.GetDatosDeContacts(copBean.getId());

            copShared.DeleteContacto(contactsBeanId.getIdcop());

            copShared.ContarContactosEnTransitions(transitionBeanM.getId());

        } catch (CstF2Exception ex) {
            log.error("ERROR. ", ex);
            addFieldError("KnkeyIncorrecta", "Ocurrio un Error: " + ex.getMessage());
            return ERROR_SESSION;

        }
        return SUCCESS;
    }
}
